package com.stonedt.spider.actionInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.stonedt.spider.entity.StonedtUser;

public class AdminInterceptor implements HandlerInterceptor{



	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		 HttpSession session = request.getSession();
		 StonedtUser obj = (StonedtUser) session.getAttribute("User");
		 String contentPath = request.getContextPath();
	      if(null == obj){
	    	  System.out.println("———————拦截器————————");
	    	  //还未登录，需要先登录
	    	  response.sendRedirect(contentPath + "/");
	      	  //request.getRequestDispatcher("/").forward(request, response);
	          return false;
	      }
	      return true;
		
		
		
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
	
		

}
